//
//  ZYVisitorView.swift
//  WBBeta1
//
//  Created by wustzhy on 16/8/10.
//  Copyright © 2016年 Yestin. All rights reserved.
//

import UIKit
import SnapKit
class ZYVisitorView: UIView {
    // MARK: - 01 声明 闭包，目的：让VisitorVC帮忙做事
    var closureVST:(()->())?
    
    override init(frame:CGRect){
        super.init(frame:frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
// MARK: - 提供外界调用
    func setupVisitorViewInfo(message:String?,imgName:String?){
        if let msg = message,let img = imgName{
            messageLabel.text = msg
            houseImageView.image = UIImage(named: img)
            //隐藏圈圈
            circleImageView.hidden = true
        }else{
            //nil代表首页
            rotateCircleImage()
        }
    }
    
    func setupUI(){
        
        self.addSubview(circleImageView)
        self.addSubview(maskImageView)
        self.addSubview(houseImageView)
        self.addSubview(messageLabel)
        self.addSubview(registerBtn)
        self.addSubview(loginBtn)
        
        circleImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
            }
        maskImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
            }
        houseImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(maskImageView.snp_bottom).offset(16)
            make.centerX.equalTo(self)
            make.height.equalTo(36)
        }
        registerBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(maskImageView)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.size.equalTo(CGSize(width: 100, height: 36))/////////////
        }
        loginBtn.snp_makeConstraints { (make) -> Void in
            make.size.top.equalTo(registerBtn)
            make.trailing.equalTo(messageLabel)
        }
    }
    
    // 圆圈
//    private lazy var circleImageView:UIImageView = UIImageView(image: UIImage(named:"visitordiscover_feed_image_smallicon"))  //01way
    private lazy var circleImageView:UIImageView = UIImageView(imgName: "visitordiscover_feed_image_smallicon")//02way,便利构造函数   Extension+UIImageView
    // 遮挡
    private lazy var maskImageView:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    // 屋子
    private lazy var houseImageView:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    // 文字
    private lazy var messageLabel:UILabel = {
       let msgLabel = UILabel()
        msgLabel.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        msgLabel.textColor = AppThemeColor
        msgLabel.font = UIFont.systemFontOfSize(15)
        //宽度、行数、居中
        msgLabel.preferredMaxLayoutWidth = 240////////////////
        msgLabel.numberOfLines = 0
        msgLabel.textAlignment = .Center
        
        return msgLabel
    }()
    // 注册 按钮
    private lazy var registerBtn:UIButton = {
       let rgstBtn = UIButton()
        rgstBtn.addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)
        //文字－－内容、颜色、字体
        rgstBtn.setTitle("注册", forState: UIControlState.Normal)
        rgstBtn.setTitleColor(AppThemeColor, forState: UIControlState.Normal)
        rgstBtn.titleLabel?.font = UIFont.systemFontOfSize(15)
        //图片
//        rgstBtn.setImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        rgstBtn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        return rgstBtn
    }()
    // 登陆
    private lazy var loginBtn:UIButton = {
        let logBtn = UIButton()
        logBtn.addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)
        //文字－－内容、颜色、字体
        logBtn.setTitle("登陆", forState: UIControlState.Normal)
        logBtn.setTitleColor(AppThemeColor, forState: UIControlState.Normal)
        logBtn.titleLabel?.font = UIFont.systemFontOfSize(15)
        //图片
        logBtn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        
        return logBtn
    }()
    
    func rotateCircleImage(){
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = M_PI * 2
        anim.duration = 10
        anim.repeatCount = MAXFLOAT
        anim.removedOnCompletion = false/////////////
        circleImageView.layer.addAnimation(anim, forKey: nil)
        
    }
    
    @objc private func buttonClick(){
    // MARK: - 03 执行闭包 
        closureVST?()
//        closureVST!()//! no?
        
    }
    
}





